package com.ts.view

import android.graphics.SurfaceTexture
import android.opengl.GLSurfaceView
import javax.microedition.khronos.egl.EGLConfig
import javax.microedition.khronos.opengles.GL10

class CameraXSurfaceView:GLSurfaceView.Renderer, SurfaceTexture.OnFrameAvailableListener {
    var mCameraXView:CameraXView?=null
    private var mCameraTexure: SurfaceTexture? = null
    private var textures: IntArray?= IntArray(1)
    constructor(mCameraXView: CameraXView?) {
        this.mCameraXView = mCameraXView
    }

    override fun onSurfaceCreated(gl: GL10?, config: EGLConfig?) {
        textures?.get(0)?.let { mCameraTexure?.attachToGLContext(it) }
        mCameraTexure?.setOnFrameAvailableListener(this)

    }

    override fun onSurfaceChanged(gl: GL10?, width: Int, height: Int) {

    }

    override fun onDrawFrame(gl: GL10?) {

    }

    override fun onFrameAvailable(surfaceTexture: SurfaceTexture?) {
        mCameraTexure?.updateTexImage()
    }
}